/*
 $command = 'phantomjs '.'phantomjs\123.js';
 exec($command,$out);
 */
var args = require('system').args;
var page = require('webpage').create();

var url = args[1];

var output = args[2];//存储文件路径和名称
function result($r) {
    $r = typeof($r)==='string'? $r: 'json://'+JSON.stringify($r);
    console.log('[##--CONTENT--##]'+$r+'[/##--CONTENT--##]');
}
// page.viewportSize = { width: 1000, height: 1000 };//设置长宽
page.settings.userAgent ='Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36';
// page.paperSize = { width:'1000px',height:'1000px', margin:{left:'0.1cm',top:'0.1cm'}};
page.paperSize = {
        width:1000,height:1000,
        margin: "0.01cm"/*,
        header: {
            height: "0.1cm",
            contents: phantom.callback(function(pageNum, numPages) {return "";})
        },
        footer: {
            height: "0.1cm",
            contents: phantom.callback(function(pageNum, numPages) {return "";})
        }*/
    };
// page.zoomFactor = 0.5;
page.open(url, function (status) {
    if (status !== 'success') {
        console.log('Unable to load the address!');
        result({success:false,msg:'Unable to load the address!'});
        phantom.exit();
    } else {
        window.setTimeout(function () {
            page.render(output);
            result({success:true,msg:'OK'});
            phantom.exit();
        },500);
    }
});